home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat3 / Tcl / async.z / async
Encoding:
Text File  |  1998-10-30  |  10.5 KB  |  199 lines

  1.  
  2.  
  3.  
  4. TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee((((3333TTTTccccllll))))                                    TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Tcl_AsyncCreate, Tcl_AsyncMark, Tcl_AsyncInvoke, Tcl_AsyncDelete - handle
  10.      asynchronous events
  11.  
  12. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      ####iiiinnnncccclllluuuuddddeeee <<<<ttttccccllll....hhhh>>>>
  14.  
  15.      extern int ttttccccllll____AAAAssssyyyynnnnccccRRRReeeeaaaaddddyyyy;
  16.  
  17.      Tcl_AsyncHandler
  18.      TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee(_p_r_o_c, _c_l_i_e_n_t_D_a_t_a)
  19.  
  20.      TTTTccccllll____AAAAssssyyyynnnnccccMMMMaaaarrrrkkkk(_a_s_y_n_c)
  21.  
  22.      int
  23.      TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee(_i_n_t_e_r_p, _c_o_d_e)
  24.  
  25.      TTTTccccllll____AAAAssssyyyynnnnccccDDDDeeeelllleeeetttteeee(_a_s_y_n_c)
  26.  
  27. AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
  28.      Tcl_AsyncProc      *_p_r_o_c        (in)      Procedure to invoke to handle
  29.                                                an asynchronous event.
  30.  
  31.      ClientData         _c_l_i_e_n_t_D_a_t_a   (in)      One-word value to pass to _p_r_o_c.
  32.  
  33.      Tcl_AsyncHandler   _a_s_y_n_c        (in)      Token for asynchronous event
  34.                                                handler.
  35.  
  36.      Tcl_Interp         *_i_n_t_e_r_p      (in)      Tcl interpreter in which
  37.                                                command was being evaluated
  38.                                                when handler was invoked, or
  39.                                                NULL if handler was invoked
  40.                                                when there was no interpreter
  41.                                                active.
  42.  
  43.      int                _c_o_d_e         (in)      Completion code from command
  44.                                                that just completed in _i_n_t_e_r_p,
  45.                                                or 0 if _i_n_t_e_r_p is NULL.
  46.  
  47.  
  48. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  49.      These procedures provide a safe mechanism for dealing with asynchronous
  50.      events such as signals.  If an event such as a signal occurs while a Tcl
  51.      script is being evaluated then it isn't safe to take any substantive
  52.      action to process the event.  For example, it isn't safe to evaluate a
  53.      Tcl script since the interpreter may already be in the middle of
  54.      evaluating a script; it may not even be safe to allocate memory, since a
  55.      memory allocation could have been in progress when the event occurred.
  56.      The only safe approach is to set a flag indicating that the event
  57.      occurred, then handle the event later when the world has returned to a
  58.      clean state, such as after the current Tcl command completes.
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee((((3333TTTTccccllll))))                                    TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.      TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee creates an asynchronous handler and returns a token for
  75.      it.  The asynchronous handler must be created before any occurrences of
  76.      the asynchronous event that it is intended to handle (it is not safe to
  77.      create a handler at the time of an event).  When an asynchronous event
  78.      occurs the code that detects the event (such as a signal handler) should
  79.      call TTTTccccllll____AAAAssssyyyynnnnccccMMMMaaaarrrrkkkk with the token for the handler.  TTTTccccllll____AAAAssssyyyynnnnccccMMMMaaaarrrrkkkk will
  80.      mark the handler as ready to execute, but it will not invoke the handler
  81.      immediately.  Tcl will call the _p_r_o_c associated with the handler later,
  82.      when the world is in a safe state, and _p_r_o_c can then carry out the
  83.      actions associated with the asynchronous event.  _P_r_o_c should have
  84.      arguments and result that match the type TTTTccccllll____AAAAssssyyyynnnnccccPPPPrrrroooocccc:
  85.           typedef int Tcl_AsyncProc(
  86.                ClientData _c_l_i_e_n_t_D_a_t_a,
  87.                Tcl_Interp *_i_n_t_e_r_p,
  88.                int _c_o_d_e);
  89.      The _c_l_i_e_n_t_D_a_t_a will be the same as the _c_l_i_e_n_t_D_a_t_a argument passed to
  90.      TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee when the handler was created.  If _p_r_o_c is invoked just
  91.      after a command has completed execution in an interpreter, then _i_n_t_e_r_p
  92.      will identify the interpreter in which the command was evaluated and _c_o_d_e
  93.      will be the completion code returned by that command.  The command's
  94.      result will be present in _i_n_t_e_r_p->_r_e_s_u_l_t.  When _p_r_o_c returns, whatever it
  95.      leaves in _i_n_t_e_r_p->_r_e_s_u_l_t will be returned as the result of the command
  96.      and the integer value returned by _p_r_o_c will be used as the new completion
  97.      code for the command.
  98.  
  99.      It is also possible for _p_r_o_c to be invoked when no interpreter is active.
  100.      This can happen, for example, if an asynchronous event occurs while the
  101.      application is waiting for interactive input or an X event.  In this case
  102.      _i_n_t_e_r_p will be NULL and _c_o_d_e will be 0, and the return value from _p_r_o_c
  103.      will be ignored.
  104.  
  105.      The procedure TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee is called to invoke all of the handlers
  106.      that are ready.  The global variable ttttccccllll____AAAAssssyyyynnnnccccRRRReeeeaaaaddddyyyy will be non-zero
  107.      whenever any asynchronous handlers are ready;  it can be checked to avoid
  108.      calls to TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee when there are no ready handlers.  Tcl checks
  109.      ttttccccllll____AAAAssssyyyynnnnccccRRRReeeeaaaaddddyyyy after each command is evaluated and calls TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee
  110.      if needed.  Applications may also call TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee at interesting
  111.      times for that application.  For example, Tk's event handler checks
  112.      ttttccccllll____AAAAssssyyyynnnnccccRRRReeeeaaaaddddyyyy after each event and calls TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee if needed.  The
  113.      _i_n_t_e_r_p and _c_o_d_e arguments to TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee have the same meaning as for
  114.      _p_r_o_c:  they identify the active interpreter, if any, and the completion
  115.      code from the command that just completed.
  116.  
  117.      TTTTccccllll____AAAAssssyyyynnnnccccDDDDeeeelllleeeetttteeee removes an asynchronous handler so that its _p_r_o_c will
  118.      never be invoked again.  A handler can be deleted even when ready, and it
  119.      will still not be invoked.
  120.  
  121.      If multiple handlers become active at the same time, the handlers are
  122.      invoked in the order they were created (oldest handler first).  The _c_o_d_e
  123.      and _i_n_t_e_r_p->_r_e_s_u_l_t for later handlers reflect the values returned by
  124.      earlier handlers, so that the most recently created handler has last say
  125.      about the interpreter's result and completion code.  If new handlers
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee((((3333TTTTccccllll))))                                    TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee((((3333TTTTccccllll))))
  137.  
  138.  
  139.  
  140.      become ready while handlers are executing, TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee will invoke
  141.      them all;  at each point it invokes the highest-priority (oldest) ready
  142.      handler, repeating this over and over until there are no longer any ready
  143.      handlers.
  144.  
  145.  
  146. WWWWAAAARRRRNNNNIIIINNNNGGGG
  147.      It is almost always a bad idea for an asynchronous event handler to
  148.      modify _i_n_t_e_r_p->_r_e_s_u_l_t or return a code different from its _c_o_d_e argument.
  149.      This sort of behavior can disrupt the execution of scripts in subtle ways
  150.      and result in bugs that are extremely difficult to track down.  If an
  151.      asynchronous event handler needs to evaluate Tcl scripts then it should
  152.      first save _i_n_t_e_r_p->_r_e_s_u_l_t plus the values of the variables eeeerrrrrrrroooorrrrIIIInnnnffffoooo and
  153.      eeeerrrrrrrroooorrrrCCCCooooddddeeee (this can be done, for example, by storing them in dynamic
  154.      strings).  When the asynchronous handler is finished it should restore
  155.      _i_n_t_e_r_p->_r_e_s_u_l_t, eeeerrrrrrrroooorrrrIIIInnnnffffoooo, and eeeerrrrrrrroooorrrrCCCCooooddddeeee, and return the _c_o_d_e argument.
  156.  
  157.  
  158. KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  159.      asynchronous event, handler, signal
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.